<template>
	<view class="login">
		<view class="logo_div">
			<image src="../../static/logo.svg" mode=""></image>
		</view>
		<view class="form_div">
			<!-- 注意，如果需要兼容微信小程序，最好通过setRules方法设置rules规则 -->
			<u--form labelPosition="left" :model="user" ref="form1">
				<view class="item_input">
					<u-form-item prop="user.username" ref="usernameRef">
						<u--input placeholder="请输入账号" v-model='user.username' prefixIcon="account-fill" border="none"
							prefixIconStyle="font-size: 22px;color: #3c9cff;padding-left:5px">
						</u--input>
					</u-form-item>
				</view>
				<view class="item_input">
					<u-form-item prop="user.password" ref="passwordRef">
						<u--input placeholder="请输入密码" v-model="user.password" prefixIcon="lock-fill" border="none"
							:password="true" prefixIconStyle="font-size: 22px;color: #3c9cff;padding-left:5px">
						</u--input>
					</u-form-item>
				</view>
			</u--form>
			<view class="btn">
				<u-button type="primary" text="登录" @click="login"></u-button>
			</view>
			<view class="txt">
				还没有账号？<text style="color:#3c9cff" @click="to">立即注册</text>
			</view>
		</view>
		<u-modal :show="showTips" :closeOnClickOverlay="true" title="提示"
			content="此应用为作者毕设设计.如有侵权,请联系作者删除,作者联系电话:17875730473" @confirm="showTips=false" @close="showTips=false">
		</u-modal>
	</view>
</template>

<script>
	import {
		login
	} from '@/api/contents/login/login.js'
	import md5 from 'md5-node'
	export default {
		data() {
			return {
				user: {
					username: 'admin',
					password: '123456'
				},
				showTips: false,
			};
		},
		methods: {
			to() {
				uni.navigateTo({
					url: '../register/register'
				})
			},
			login() {
				const sendFormData = {
				      username: this.user.username,
				      password: md5(this.user.password),
				};
				login(sendFormData).then(res => {
					if (res.code === 0) {
						// 保存token
						uni.setStorageSync('token', res.data.token);
						this.$store.commit('updateToken', res.data.token);
						uni.hideLoading();
						uni.switchTab({
							url:'../home/home'
						})
					}else{
						uni.hideLoading();
						uni.showToast({
							icon:'none',
							title:res.message
						})
					}
				}, rej => {
					console.log(rej);
				})
			},
			
		},
		onLoad() {
			this.showTips = true;
		}
	}
</script>

<style lang="scss" scoped>
	.login {
		/* #ifdef MP-WEIXIN */
		padding-top: 6vh;

		/* #endif */
		.logo_div {
			height: 30vh;
			display: flex;
			justify-content: center;
			align-items: center;

			image {
				width: 320upx;
				height: 240upx;
			}
		}

		.form_div {
			padding: 0 120upx;

			.item_input {
				background: #f6f6f6;
				border-radius: 10upx;
				margin-bottom: 30upx;
			}

			.btn {
				padding: 30upx 0;
			}

			.txt {
				text-align: right;
				font-size: 24upx;
			}
		}

	}
</style>
